package cn.com.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.entity.UserOrderDTO;

/**
 * @author liufl
 * @version 创建时间：2017年7月19日 上午8:56:23 
 * 发送短信队列
 */
public class SendMsgQueue {
	private static Logger log = LoggerFactory.getLogger(SendMsgQueue.class);
	private static int queueSize = 1000;
	private static BlockingQueue<UserOrderDTO> queue = new ArrayBlockingQueue<UserOrderDTO>(queueSize);

	public void setQueueSize(int queueSize) {
		SendMsgQueue.queueSize = queueSize;
	}

	/**
	 * 取出用户购买订单信息
	 * 
	 * @return
	 */
	public static UserOrderDTO getMessage() {
		UserOrderDTO vo = null;
		try {
			vo = queue.take();
			log.info("takeQueue:"+vo.toString()+";;curSize:"+queue.size());
		} catch (InterruptedException e) {
			log.error("取出用户购买订单信息", e);
		}
		return vo;
	}

	/**
	 * 增加用户购买订单信息
	 * 
	 * @param vo
	 */
	public static void putMessage(UserOrderDTO vo) {
		try {
			queue.put(vo);
			log.info("putQueue:"+vo.toString()+";;curSize:"+queue.size());
		} catch (InterruptedException e) {
			log.error("增加用户购买订单信息", e);
		}
	}
	
}
